//
//  MLTabBar.swift
//  weibo
//
//  Created by manmanlang on 16/6/22.
//  Copyright © 2016年 manmanlang. All rights reserved.
//

import UIKit

class MLTabBar: UITabBar {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUIButton()
    }
    
    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
        fatalError("你即将使用xib加载视图，请初始化")
    }
    
    private func setUIButton(){
        addSubview(composeButton)
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        composeButton.center = CGPointMake(bounds.width * 0.5, bounds.height * 0.5)
        
        
        let width = bounds.width * 0.2
        
        var index = 0
        
        for subView in subviews {
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
//                print(subView)
                
                subView.frame = CGRectMake(CGFloat(index) * width, bounds.origin.y, width, bounds.height)
                
                index += 1
                
                if index == 2 {
                    index += 1
                }
            }
        }
        
    }
    
    //MARK:--懒加载一个button
    lazy var composeButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        // 设置属性
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        // 设置宽高
        button.sizeToFit()
        
        return button
        
    }()


    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */

}
